package library.and.xps.com.step.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import library.and.xps.com.step.R;
import library.and.xps.com.step.m.model.TeamRankingRes;
import library.and.xps.com.step.util.CommonUtils;

public class TeamRankingAdapter extends BaseAdapter {
    List<TeamRankingRes.ListBean> dataset = new ArrayList<>();
    Context context;

    public TeamRankingAdapter(Context context) {
        this.context = context;
    }

    public void setDataset(List<TeamRankingRes.ListBean> dataset) {
        this.dataset = dataset;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return dataset.size();
    }

    @Override
    public Object getItem(int position) {
        return dataset.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    ViewHolder vh;

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TeamRankingRes.ListBean data = dataset.get(position);
        if (convertView == null) {
            vh = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.team_ranking_item, null);
            vh.iv_team_header = (ImageView) convertView.findViewById(R.id.iv_team_header);
            vh.tv_team_ranking = (TextView) convertView.findViewById(R.id.tv_team_ranking);
            vh.tv_team_name = (TextView) convertView.findViewById(R.id.tv_team_name);
            vh.tv_team_desc = (TextView) convertView.findViewById(R.id.tv_team_desc);
            vh.tv_step_ave = (TextView) convertView.findViewById(R.id.tv_step_ave);
            convertView.setTag(vh);
        } else {
            vh = (ViewHolder) convertView.getTag();
        }

        vh.tv_team_ranking.setText(++position+"");
        vh.tv_step_ave.setText(data.getWalk()+"");
        vh.tv_team_name.setText(data.getTname() + "");
        vh.tv_team_desc.setText(data.getDescription() + "");
        CommonUtils.setupCircleImgWithToken(context, vh.iv_team_header, data.getMark() + "");

        return convertView;
    }

    class ViewHolder {
        ImageView iv_team_header;
        TextView tv_team_ranking, tv_team_name, tv_team_desc, tv_step_ave;
    }

}
